<template>
	<view class="content">
		<view class="search">
			<u-search bgColor="#fff" @change="namechange" v-model="name" margin="0 20rpx" placeholder="输入商品名称搜索"
				:showAction="false"></u-search>
		</view>
		<view class="shop">
			<view class="s-item">
				<view class="s-logo">
					<image :src="tool.img(config.logoimage)" mode=""></image>
				</view>
				<view class="s-content">
					<view class="s-name">
						{{ config.name }}
					</view>
					<view class="s-idcr">
						<text class="s-idcr1">金牌店铺</text>
						<text class="s-idcr2">{{ config.jie }}</text>
					</view>
					<view class="s-footer">
						<text>{{ config.dizhi }}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="screen">
			<view class="screen-item" :class="screenItem == 0?'newscreen':''" @tap="zong">
				<view>综合</view>
			</view>
			<view class="screen-item" @tap="xiaoliang" :class="screenItem == 1?'newscreen':''">
				<view>销量</view>
			</view>
			<view class="screen-item">
				<picker mode="selector" :range="rangeList" range-key="name" @change="jiage">
					<text :class="screenItem == 2?'newscreen':''"> 价格</text>
				</picker>
			</view>
			<view class="screen-item">
				<view class="" @tap="newfa" :class="screenItem == 3?'newscreen':''">
					最新
				</view>
			</view>
		</view>
		<view class="hot-list">
			<view class="shop-list">
				<bookList :hotList="List"></bookList>
			</view>
		</view>
		<view class="" style="width: 100%;height: 80rpx;">

		</view>
	</view>
</template>

<script>
	import tool from '@/utils/tool.js'
	import bookList from '../../components/book-list.vue'
	export default {
		components: {
			bookList
		},
		data() {
			return {
				screenItem: 0,
				rangeList: [{
						"name": "升序"
					},
					{
						"name": "降序"
					}
				],
				show: false,
				tool: tool,
				notice: '',
				navList: [],
				banner: [],
				hotList: [],
				couponList: [],
				List: [],
				page: 1,
				config: '',
				name: ''
			}
		},
		onLoad() {
			this.Getconfig()
			this.GetList()
		},
		onShow() {
			if(!uni.getStorageSync('token')){
				this.gettoken()
			}
		},
		onPullDownRefresh() {
			this.GetList()
			uni.stopPullDownRefresh()
		},
		onReachBottom() {
			this.page++
			this.GetList()
		},
		methods: {
			gettoken() {
				this.$http.Post('user/register', {}, (result) => {
					console.log(result, '?')
					uni.setStorageSync('userinfo', result.data.userinfo)
					uni.setStorageSync('token', result.data.userinfo.token)
				})
			},
			namechange() {
				this.page = 1
				this.GetList()
			},
			Getconfig() {
				this.$http.Post('zter/shopInfo', {}, (result) => {
					this.config = result.data
				})
			},
			zong() {
				this.page = 1
				this.screenItem = 0
				this.order = ''
				this.GetList()
			},
			newfa() {
				this.screenItem = 3
				this.page = 1
				this.order = 'id desc'
				this.GetList()
			},
			jiage(e) {
				this.page = 1
				this.screenItem = 2
				let index = e.detail.value
				if (index == 0) {
					this.order = 'price asc'
				} else {
					this.order = 'price desc'
				}

				this.GetList()
			},
			xiaoliang() {
				this.screenItem = 1
				this.order = ''
				this.page = 1
				this.GetList()
			},
			GetList() {
				uni.showLoading({
					title: '正在加载'
				})
				this.$http.Post('zter/shopList', {
					page: this.page,
					order: this.order,
					name: this.name
				}, (result) => {
					uni.hideLoading()
					if (this.page == 1) {
						this.List = []
					}
					this.List = this.List.concat(result.data.data)
				})
			},
			Godetails(item) {
				uni.navigateTo({
					url: '/pages/book/index?id=' + item.id
				})
			},
			Gomore() {
				uni.navigateTo({
					url: '/pages/coupon/index'
				})
			},
		}
	}
</script>

<style lang="scss">
	.shop {
		width: 100%;
		height: 200rpx;
		background-color: #fff;
		margin: 0rpx 0 20rpx 0;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.s-item {
		width: 94%;
		height: 80%;
		display: flex;
		align-items: center;
	}

	.s-logo {
		// width: 25%;
		height: 100%;
	}

	.s-logo>image {
		width: 200rpx;
		height: 160rpx;
		border-radius: 10rpx;
	}

	.s-content {
		width: 75%;
		height: 100%;
		padding-left: 35rpx;
	}

	.s-name {
		margin-top: 10rpx;
		color: #000;
		font-weight: bold;
		font-size: 34rpx;
	}

	.s-idcr {
		font-size: 28rpx;
		margin-top: 10rpx;
		display: flex;
		align-items: center;
	}

	.s-idcr1 {
		background-color: #fff0c9;
		color: #c49c3f;
		border: 1rpx solid #c49c3f;
		border-radius: 12rpx;
		padding: 5rpx 10rpx;
		font-weight: bold;
		font-size: 28rpx;
	}

	.s-idcr2 {
		font-size: 26rpx;
		color: #c49c3f;
		padding-left: 10rpx;
	}

	.s-footer {
		display: flex;
		align-items: center;
		font-size: 28rpx;
		color: #ccc;
		margin-top: 10rpx;
	}

	.search {
		width: 100%;
		height: 100rpx;
		display: flex;
		align-items: center;
		// background-color: #fff;
		margin-top: 20rpx;
	}

	.swiper {
		height: 720rpx;
	}

	.grid-text {
		font-size: 14px;
		color: #909399;
		padding: 10rpx 0 20rpx 0rpx;
		/* #ifndef APP-PLUS */
		box-sizing: border-box;
		/* #endif */
	}

	.nav {
		width: 100%;
		background-color: #fff;
		margin-top: 20rpx;
		display: flex;
		flex-wrap: wrap;
		padding: 20rpx 0;
	}

	.nav-list {
		margin: 20rpx 0;
		width: 20%;
		height: 50%;
	}

	.nav-img {
		width: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.nav-img>image {
		width: 85rpx;
		height: 85rpx;
	}

	.nav-name {
		margin-top: 20rpx;
		width: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
		color: #3c3c3c;
		font-size: 26rpx;
		text-align: center;
	}

	.hot-list {
		margin-top: 20rpx;
	}

	.shop-list {
		padding: 0rpx 25rpx;
	}

	.screen {
		width: 100%;
		height: 80rpx;
		background-color: #fff;
		display: flex;
		align-items: center;
	}

	.screen-item {
		width: 25%;
		height: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
		color: #3c3c3c;
		font-size: 28rpx;
	}

	.counpon-right {
		width: 20%;
		height: 100%;
		display: flex;
		align-items: center;
		justify-content: flex-end;
	}

	.right {
		width: 60%;
		color: #fff;
		font-size: 26rpx;
	}

	.counpon-block-2 {
		width: 30rpx;
		height: 200rpx;
		position: absolute;
		left: -32rpx;
	}

	.block-more {
		margin-bottom: 10rpx;
		width: 25rpx;
		height: 25rpx;
		border-radius: 50%;
		background-color: #f6f6f6;
	}

	.newscreen {
		font-weight: bold;
		color: #ff5502;
	}
</style>